package yagwl.client.widget;

import yagwl.client.model.ItemDTO;
import yagwl.client.model.ItemListCache;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.DialogBox;

/**
 * Abstract class that must be extended when implementing LOV dialog boxes
 */
public abstract class AbstractSelectItemDialogBox extends DialogBox {
  
  protected final PagedFlexTable table;  // TODO P2 use PagedCellTable
  private ItemDTO selectedItemDTO; 

  public AbstractSelectItemDialogBox(ItemListCache listCache) {
    table = new PagedFlexTable(listCache);
    // setGlassEnabled(true);
    setAnimationEnabled(true);
    table.addButton("Cancel", new ClickHandler() {

      @Override
      public void onClick(ClickEvent event) {
        selectedItemDTO = null;
        AbstractSelectItemDialogBox.this.hide();
      }
    });
  }

  
  protected ItemDTO getSelectedItem() {
    return selectedItemDTO;
  }

  protected void setSelectedListItem(ItemDTO itemDTO) {
    this.selectedItemDTO = itemDTO;
  }
  
}
